define(["jquery","vue","layer",'common'],function ($,Vue,layer,common){
    const Controller = {
        index:function (){
            var app = Vue.createApp({
                data(){
                    return {
                        seachObj:[
                            {
                                field:"sort",
                                show:false,
                                value:'id'
                            },
                            {
                                field:"order",
                                show:false,
                                value:'asc'
                            }
                        ],
                        dataObj:{
                            total:0,
                            rows:[],
                            limit:10,
                            page:1
                        },
                        //打开搜索
                        openSeach:false,
                        //显示搜索
                        seachShow:false
                    }
                },
                created(){
                    // console.log(Config,'ccccccccccccccccc')
                    this.indexLoadData()
                    this.loadSeach()
                    // this.indexCreateHeight()
                },
                methods:{
                    ...common,

                    selectable(row){
                        if(row.id!=1){
                            return true
                        }
                        return false
                    },
                    handleSizeChange(e){
                        this.dataObj.limit = e
                        this.dataObj.page = 1
                        this.indexLoadData()
                    },
                    handleCurrentChange(e){
                        this.dataObj.page = e
                        this.indexLoadData()
                    },
                    handleEdit(row,pk='id'){
                        let url = Config.controllername+`/edit?ids=${row[pk]}`
                        let that = this;
                        this.open2(url,{
                            title:"修改",
                            callback:function (res){
                                that.indexLoadData()
                                window.parent.getUserInfo()
                            }
                        })
                    }
                }
            })
            common.loadELEMENT(app,false)
            app.mount("#app");
        },
        add:function (){
            var app = Vue.createApp({
                data(){
                    return {
                        height:600,
                        form:{
                            username:"",
                            nickname:"",
                            password:"",
                            avatar:"",
                            email:"",
                            status:1,
                            group_id:""
                        },
                        additional:{
                            group:[]
                        },
                        groups:[],
                        rules:{

                        },
                        uploadurl:Config.upload.uploadurl
                    }
                },
                created(){
                    // console.log(Config,'ccccccccccccccccccc')
                    this.getGroup()
                    // this.indexCreateHeight(400)
                },
                methods: {
                    ...common,
                    getGroup(){
                        let url = 'auth.group/index'
                        let that = this
                        this.moduleGet(url,null,function (res){
                            // console.log(res,'res')
                            that.groups = res.rows
                            // app.group = res.data
                        })
                    },
                }
            })
            common.loadELEMENT(app,['icon'])
            app.mount("#app");
        },
        edit:function (){
            var app = Vue.createApp({
                data(){
                    return {
                        form:{
                            username:"",
                            nickname:"",
                            password:"",
                            avatar:"",
                            email:"",
                            status:1,
                            group_id:""
                        },
                        additional:{
                            group:[]
                        },
                        groups:[],
                        rules:{

                        },
                        uploadurl:Config.upload.uploadurl,
                    }
                },
                created(){
                    // console.log(Config,'ccccccccccccccccccc')
                    this.getGroup()
                    let url = Config.moduleurl+'/'+Config.controllername+`/index`;
                    // console.log(url)
                    let ob = this.getQueryParameterAsJson()
                    let that = this;
                    // console.log(ob,'oooooooooooooo')
                    if(ob&&ob.ids){
                        let data = {
                            keyField:'id',
                            keyValue:ob.ids
                        };
                        $.post(url,data,function (res){
                            if(res.total>0){
                                let data = res.list[0]
                                if(data.group_id){
                                    // console.log(that.additional,'ddddddddddddd')
                                    that.additional.group = data.group_id
                                }
                                let form = that.form||{}
                                for(let key in data){
                                    if(form[key]!==undefined&&key!='password'){
                                        form[key] = data[key]
                                    }
                                }
                                that.form = form
                            }
                        })
                    }
                    // console.log(this.form,'ffffffffffffffffff')
                },
                methods: {
                    ...common,
                    getGroup(){
                        let url = 'auth.group/index'
                        let that = this
                        this.moduleGet(url,null,function (res){
                            // console.log(res,'res')
                            that.groups = res.rows
                            // app.group = res.data
                        })
                    },
                }
            })
            common.loadELEMENT(app,['icon'])
            
            app.mount("#app");
        }

    }
    return Controller;
})